import game from "./game";

const { ccclass, property } = cc._decorator;

@ccclass
export default class airplaneNode extends cc.Component {

  direction: cc.Vec2 = null;
  speed: number = 10;
  // onLoad () {}
  onCollisionEnter(other: cc.Collider, self: cc.Collider) {
    game.inst.gameover();
  }
  start() {
    this.schedule(this.timer,0.2,cc.macro.REPEAT_FOREVER,0.1)
  }
  timer(){
    //动态创建子弹节点 然后挂载到canvas节点下
    let bulletNode = game.inst.createBullet();
    bulletNode.setPosition(this.node.x,this.node.y+this.node.height);
    this.node.parent.addChild(bulletNode);
  }
  update(dt) {
    if (!this.direction) return;
    let dx = this.direction.x * this.speed;
    let dy = this.direction.y * this.speed;
    let nodePosition = this.node.getPosition();
    nodePosition.x += dx;
    nodePosition.y += dy;
    this.node.setPosition(nodePosition);


  }
}
